<?php
/**
 * Created by b17
 * 2/28/12 9:11 PM
 */

class Logger
{
    private $_fileName;

    private $_fp;

    private static $_instance = null;

    private function __construct()
    {
        $this->_fileName = __DIR__ . DIRECTORY_SEPARATOR . 'cron.log';
        $this->_fp = fopen($this->_fileName, 'a');
    }

    public function log($message, $module)
    {
        $now = new \DateTime();
        $content = "[" . $now->format('Y-m-d H:i:s') . "][$module] " . $message . PHP_EOL;
        fwrite($this->_fp, $content);
    }

    public function __destruct()
    {
        fclose($this->_fp);
    }

    public static function getInstance()
    {
        if (self::$_instance === null) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
}
